# -*- coding: utf-8 -*-
import smtplib
from email.mime.text import MIMEText
import config
mail_host=config.mail_host
mail_user=config.mail_user
mail_pass=config.mail_pass
mail_postfix=config.mail_postfix

def read_content(path):
    try:
        with open(path, 'r') as f:
            content = f.read()
        return content
    except Exception as e:
        print(str(e.__class__))
        print(str(e))
        return '脚本异常'

def send_mail(to_list,sub,content,subtype='html'):  #to_list：收件人；sub：主题；content：邮件内容
    me="notify"+"<"+mail_user+"@"+mail_postfix+">"   #这里的hello可以任意设置，收到信后，将按照设置显示
    msg = MIMEText(content,_subtype=subtype,_charset='utf-8')    #创建一个实例，这里设置为html格式邮件
    msg['Subject'] = sub    #设置主题
    msg['From'] = me
    msg['To'] = ",".join(to_list)

    try:
        s = smtplib.SMTP()
        s.connect(mail_host)  #连接smtp服务器
        s.login(mail_user,mail_pass)  #登陆服务器
        s.sendmail(me, to_list, msg.as_string())  #发送邮件
        s.close()
        return True
    except Exception, e:
        print str(e)
        return False

def send_sms(to_list, message):
    pass

